//
//  EGMWriteMassData2Device.h
//  BleSports
//
//  Created by hh on 15/12/31.
//  Copyright © 2015年 egoman. All rights reserved.
//

#import "EGMBleSportsOperation.h"

#define DEF_WRITE_MASS_CMD_TIMEOUT_SECOND 2*60

@protocol EGMBufferSizeDelegate <NSObject>
-(void) onGetBufferSize:(NSInteger)bufferSize isCheckingWriteFinish:(BOOL)isCheckingWriteFinish;
@end


@interface EGMWriteMassData2Device<ObjectType> : EGMMassDataCmd<EGMBufferSizeDelegate>
@property(nonatomic,strong) NSData *data;
@property(nonatomic,assign) NSInteger packetAmount;
@property(nonatomic,assign) NSInteger packetIndex;
@property(nonatomic,assign) NSInteger willWritePackets;
@property(nonatomic,strong) ObjectType bleOperation;
//@property(nonatomic,strong) EGMBleSportsOperation *bleOperation;

-(instancetype)initWithBleOperation:(ObjectType)bleOperation dataOfWrite:(NSData*)dataOfWrite;
//-(instancetype)initWithBleOperation:(EGMBleSportsOperation*)bleOperation dataOfWrite:(NSData*)dataOfWrite;
-(NSInteger)getDataLengthInOnePacket;
-(void) writeOnePacket:(NSInteger)packetAmount packetIndex:(NSInteger)packetIndex content:(NSData*)content;
-(void) finishWriteData;
-(void) doWriteDataOfBufferSize:(NSInteger)bufferSize;
-(NSInteger) calculatePacketAmount:(NSData*)data;
-(void) doBufferSizeBusy:(BOOL)isCheckingWriteFinish;
//-(void)onGetAck;
//-(void)onWriteTimeout;
-(void)addTimeoutCallback:(NSInteger)willWritePackets;
-(float)getTimeoutSecond:(NSInteger)willWritePackets;
//-(void)cancelTimeoutCallback;
//-(void) beginWriteData;
//-(void) writeCmdOfReadBufferSize:(BOOL)isCheckingWriteFinish;
//-(void) onGetBufferSize:(NSInteger)bufferSize isCheckingWriteFinish:(BOOL)isCheckingWriteFinish;
//-(void) writeCrcPacket:(NSInteger)packetAmount crcPacketIndex:(NSInteger)crcPacketIndex crcData:(NSData*)data;
//-(BOOL)isBufferSizeBusy:(NSInteger)bufferSize;
@end


@interface EGMOnBufferSizeMassDataListener : EGMOnSportsMassDataListener
@property(nonatomic,strong) id<EGMBufferSizeDelegate> delegate;
@property(nonatomic,assign) BOOL isCheckingWriteFinish;

-(instancetype)initWithDelegate:(id<EGMBufferSizeDelegate>)delegate isCheckingWriteFinish:(BOOL)isChecking;
@end


#define ACK 0x01
#define NACK 0x02
#define STOP 0x03
@interface OnAckMassDataListener : EGMOnSportsMassDataListener
@property(nonatomic,strong) EGMWriteMassData2Device *writer;
-(instancetype)initWithDataWriter:(EGMWriteMassData2Device*)writer;
@end
